<%-- 
    Document   : topic
    Created on : 26 janv. 2010, 17:03:08
    Author     : Puja, Szymanski
--%>

<%@page import="fr.ensisa.pujaszymanski.*, java.util.*, java.text.*" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
    if (this.getServletContext().getAttribute("forum") == null) {
        %>
        <jsp:forward page="index.jsp"/>
        <%
    }

    long idTopic = -1;
    
    if(request.getParameter("idTopic") != null) {
	idTopic = Long.valueOf(request.getParameter("idTopic"));
    }
    else if(request.getAttribute("idTopic") != null) {
	idTopic = (Long) request.getAttribute("idTopic");
    }
    else {
	%>
        <jsp:forward page="index.jsp"/>
        <%
    }

    Forum f = (Forum) this.getServletContext().getAttribute("forum");
    Topic topic = f.getTopic(idTopic);
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>MiniForum - Puja, Szymanski</h1>
	<hr />
	<h2><%= topic.getTitle() %></h2>
        <%
            if(topic.isEmpty())
		out.write("Aucun message.");
	    else {
		Iterator<Message> it = topic.iterator();
		while (it.hasNext()) {
		    Message m = it.next();
		    out.write("Post&eacute; le ");
                    out.write(DateFormat.getDateInstance(DateFormat.MEDIUM).format(m.getDate()));
                    out.write(" par ");
                    out.write(m.getAuthor());
		    out.write(" | ");
		    out.write(m.getText());
		    out.write("<br />\n");
		}
	    }
        %>

	<h2>Ajouter un message</h2>

	<form action="new_message?idTopic=<%= idTopic %>" method="post">
	    <p>Message : <textarea rows="5" cols="100" name="message"></textarea></p>
	    <p><input type="submit" name="buttonNewMessage" value="Ajouter" />
	</form>
    <hr/>

    <p><a href="index.jsp">Retour &agrave; l'accueil</a></p>
    
    </body>
</html>
